home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3015 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  50 lines

  1. Path: prodigy.com!usenet
  2. From: WCME76A@prodigy.com (Shane Morrell)
  3. Newsgroups: comp.lang.c++
  4. Subject: C++ display ASCII file
  5. Date: 21 Jan 1996 17:17:01 GMT
  6. Organization: Prodigy Services Company  1-800-PRODIGY
  7. Distribution: world
  8. Message-ID: <4dtsed$309o@useneta1.news.prodigy.com>
  9. NNTP-Posting-Host: inugap5.news.prodigy.com
  10. X-Newsreader: Version 1.2
  11.  
  12. I am dabbling in C++ (see code below) and need a little assistance with 
  13. reading an ASCII file using the stream functions.  This works like the 
  14. dos TYPE command well, I want it to anyway. It does fine except it will 
  15. not recognize the 'whitespace' in the text file.  When it is displayed, 
  16. everything is crammedtogetherlikethis.  Arrrgh!
  17.  
  18. Shane  //    shane@prodigy.com
  19. =========================================
  20.  
  21. #include<iostream.h>
  22. #include<fstream.h>
  23.  
  24. void main(int argc,char* argv[]) {
  25.     if(argc<2){
  26.         cout << "\nFilename parameter needed!";
  27.              << endl;
  28.     }
  29.     else{
  30.         ifstream src(argv[1], ios::nocreate);
  31.             if(src) {
  32.                 char c;
  33.  
  34.                 src >> c;
  35.                while(!src.eof()) {
  36.                      cout << c;
  37.                      src >> c;
  38.                }
  39.              
  40.                src.close();
  41.           }
  42.         else{                    cout << argv[1]
  43.                          << " does not exist" 
  44.                          << endl;
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50.